package com.taoyibao.hongcanting.ui.restaurant.area;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.taoyibao.hongcanting.R;
import com.taoyibao.hongcanting.base.BaseRelativeLayout;
import com.taoyibao.hongcanting.model.GiftInfoModel;
import com.taoyibao.hongcanting.utils.CodeUtils;
import com.taoyibao.hongcanting.utils.GlideUtil;

/**
 * @author TangAnna
 * @description: item礼物
 * @date :${DATA} 11:26
 */
public class ItemGiftArea extends BaseRelativeLayout<GiftInfoModel> {
    private GiftInfoModel mModel;
    /**
     * 最外层的背景
     */
    private LinearLayout mLayout;
    /**
     * 礼物图片
     */
    private ImageView mIvImg;
    /**
     * 礼物名称
     */
    private TextView mTvName;
    /**
     * 礼物价格
     */
    private TextView mTvPrice;

    public ItemGiftArea(Context context) {
        super(context);
    }

    public ItemGiftArea(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ItemGiftArea(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void initView(Context context, AttributeSet attrs, int defStyleAttr) {
        mLayout = findViewById(R.id.layout_itemGift_bg);
        mIvImg = findViewById(R.id.iv_itemGift_img);
        mTvName = findViewById(R.id.tv_itemGift_name);
        mTvPrice = findViewById(R.id.tv_itemGift_price);
    }

    @Override
    public void setData(GiftInfoModel data) {
        if (data != null) {
            mModel = data;
        }
        //名称
        if (!TextUtils.isEmpty(data.gift_name)) {
            mTvName.setText(data.gift_name);
        }
        //价格
        mTvPrice.setText(CodeUtils.formatAmountUnit(data.price));
        //图片
        GlideUtil.getInstance().loadDefaultImage(getContext(), data.img_url, mIvImg);
        //选择框
        if (data.isCheckd) {
            mLayout.setBackgroundResource(R.drawable.shape_stroke_small_raduis_f46);
        } else {
            mLayout.setBackgroundResource(R.drawable.shape_stroke_small_raduis_white);
        }
    }

    @Override
    protected int bindLayout() {
        return R.layout.item_gift;
    }
}
